package com.csaba.connector.web.util;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import com.csaba.util.LoggerHelper;

public class NoTrustFactory
{
	private final static Logger logger = LoggerHelper.getDefaultLogger();

	public static SSLContext installCert()
	{
		try
		{

			final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
			{
				@Override
				public java.security.cert.X509Certificate[] getAcceptedIssuers()
				{
					return null;
				}

				@Override
				public void checkClientTrusted( final java.security.cert.X509Certificate[] certs, final String authType )
				{
				}

				@Override
				public void checkServerTrusted( final java.security.cert.X509Certificate[] certs, final String authType )
				{
				}
			} };

			final SSLContext sslContext = SSLContext.getInstance("SSL");
			sslContext.init(null, trustAllCerts, null);

			return sslContext;
		}
		catch ( final Exception ex )
		{
			logger.log(Level.SEVERE, "Error initializing certificate store.", ex);
		}
		return null;
	}

}
